(Mostly) tmap vs ggplot2
Decided to give it a go
<spoilers> It was… interesting?!
Also: hard
tmap and ggplot2Two great packages for thematic mapping in R
Both lean into the so-called grammar of graphics
ggplot2Based on The Grammar of Graphics
Aesthetic ‘mappings’ between variables in data and visual variables
Focused on applying ‘geometries’—geom_point, geom_line, geom_bar, etc.—to data, e.g.
ggplot2(dataset) +
geom_point(aes(x = var1, y = var2))
One geometry option is geom_sf for making maps
# read the data
ak <- st_read("../data/ak-city-demographics-2018.gpkg")
nz <- st_read("../data/nz.gpkg")
bb <- st_bbox(ak)
map1 <- ggplot(nz) +
geom_sf(lwd = 0) +
geom_sf(data = ak, aes(fill = pop)) +
coord_sf(xlim = c(bb[1], bb[3]), ylim = c(bb[2], bb[4])) +
guides(fill = guide_legend(title = "Population")) +
theme(panel.background = element_rect(fill = "#bbeeff"))
map1tmapA ggplot-a-like tailored to thematic maps
In place of aes() to specify the data-visual variable relations, there are functions tm_polygons, tm_borders, tm_fill, tm_lines, and so on
Also provides tm_scalebar, tm_compass and other ‘map frills’
ggplot2tmapSee it at dosull.github.io/30-day-maps-2023
You don’t need a theme
Cheat and forgive yourself
Don’t do it for an audience
tmap vs ggplot2
tmap is likely still preferable to ggplot2 for basic thematic maps
Either is very good and R is an option very much worth considering for routine mapping applications
github.com/DOSull/30-day-maps-2023
github.com/DOSull/weaving-space
Reach me on LinkedIn
Maptime! Wellington, 20 March 2024